﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Database;
public partial class admin_SuachitietDDH : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var pm = new checkLogin();
        pm.redirectToLoginPage();
        if (!IsPostBack)
            {
                if (Session["tenkh"] == "Admin")
                {
                    Response.Redirect("Login.aspx");
                }
                else
                {
                    ddlmamay.DataSource = MayTinh.DSMaMay().Tables[0];
                    ddlmamay.DataTextField = "tenmay";
                    ddlmamay.DataValueField = "mamay";
                    ddlmamay.DataBind();

                    LayThongTin();
                }
            }
       

        }
        public void LayThongTin()
        {
            int maddh = int.Parse(Request.QueryString["maddh"].ToString());            
            CT_DonDatHang ctddh = new CT_DonDatHang();            
            ctddh = ctddh.ThongTinCTDDH(maddh);
            this.txtMaDDH.Text = ctddh.Maddh.ToString();
            this.txtSoLuong.Text = ctddh.Soluong.ToString();
            this.txtGiaBan.Text = ctddh.Giaban.ToString();
            this.ddlmamay.SelectedValue = ctddh.Mamay.ToString();

        }

        protected void btSave_Click(object sender, EventArgs e)
        {
            int maddh = int.Parse(txtMaDDH.Text);
            int mamay = int.Parse(ddlmamay.SelectedValue.ToString());
            int soluong = int.Parse(txtSoLuong.Text);
            float giaban = float.Parse(txtGiaBan.Text);
            CT_DonDatHang ctddh = new CT_DonDatHang();
            ctddh.CapNhatCTDDH(maddh,mamay, soluong, giaban);
            Response.Redirect("HienthichitietDDH.aspx");
        }

        protected void btCancel_Click(object sender, EventArgs e)
        {
            this.txtSoLuong.Text = "";
            this.txtGiaBan.Text = "";
        }
    
}
